<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>管理员</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8" />
    <link rel="stylesheet" href="/static/system/css/font.css">
    <link rel="stylesheet" href="/static/system/css/xadmin.css">
    <script src="/static/system/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/static/system/js/xadmin.js"></script>
    <!--[if lt IE 9]>
          <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
          <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->
</head>

<body>
    <div class="x-nav">
        <span class="layui-breadcrumb">
            <a href="javascript:;">首页</a>
            <a href="javascript:;">系统管理</a>
            <a><cite>管理员</cite></a>
        </span>
        <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="resetting()"
            title="刷新">
            <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
    </div>
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-body ">
                        <form class="layui-form layui-col-space5" action="{:url('showList')}" method="get">
                            <button type="button" class="layui-btn" onclick="user_add()"><i
                                    class="layui-icon">&#xe61f;</i>添加管理员</button>
                            <div class="layui-inline layui-show-xs-block">
                                <input type="text" name="keyword" placeholder="用户名/邮箱/手机号" autocomplete="off"
                                    class="layui-input" value="{:input('get.keyword')}">
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <button class="layui-btn" lay-filter="sreach"><i
                                        class="layui-icon">&#xe615;</i></button>
                            </div>
                        </form>
                    </div>
                    <div class="layui-card-body layui-table-body layui-table-main">
                        共{$count}条数据
                        <table class="layui-table layui-form" lay-size="sm">
                            <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>用户名</th>
                                    <th>性别</th>
                                    <th>手机</th>
                                    <th>邮箱</th>
                                    <th>状态</th>
                                    <th>最后登陆时间</th>
                                    <th>角色</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                {volist name="$userList" id="user" empty="暂时没有数据" }
                                <tr>
                                    <td>{$user.admin_id}</td>
                                    <td>{$user.username}</td>
                                    <td>
                                        {if ($user.gender == 0)}
                                        女
                                        {/if}
                                        {if ($user.gender == 1)}
                                        男
                                        {/if}
                                    </td>
                                    <td>{$user.phone}</td>
                                    <td>{$user.email}</td>
                                    <td>
                                        {if ($user.state == 0)}
                                        已禁用
                                        {/if}
                                        {if ($user.state == 1)}
                                        正常
                                        {/if}
                                    </td>
                                    <td>{:date("Y-m-d H:i:s",$user.last_login_time)}</td>
                                    <td>
                                        {if ($user.r_name != "")}
                                        {$user.r_name}
                                        {else}
                                        --
                                        {/if}
                                    </td>
                                    <td class="td-manage">
                                        <a title="编辑" onclick="user_upd('{$user.admin_id}')" href="javascript:;">
                                            <i class="layui-icon">&#xe642;</i>
                                        </a>
                                        </a>
                                        <a title="删除" onclick="user_del('{$user.admin_id}')" href="javascript:;">
                                            <i class="layui-icon">&#xe640;</i>
                                        </a>
                                    </td>
                                </tr>
                                {/volist}
                            </tbody>
                        </table>
                    </div>
                    <div class="layui-card-body ">
                        <div class="page">
                            {$userList|raw}
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
<script>
    layui.use(['form', 'layer', 'jquery']);
    var $ = layui.jquery;

    // 刷新
    function resetting() {
        location.href = "{:url('showList')}";
    }

    // 添加管理员
    function user_add() {
        xadmin.open("添加管理员", "{:url('userAdd')}", 600, 450);
    }

    function user_upd(admin_id) {
        xadmin.open("修改管理员", "{:url('userUpd')}?admin_id=" + admin_id, 600, 450);
    }

    // 删除
    function user_del(admin_id) {
        layer.confirm('确认要删除吗？', function (index) {
            $.ajax({
                url: "{:url('userDel')}",
                type: "POST",
                data: {
                    admin_id: admin_id
                },
                success: function (res) {
                    console.log(res);
                    console.log(res.code);
                    if (res.code == 0) {
                        layer.msg(res.msg, { icon: 1, time: 1000 }, function () {
                            var index = parent.layer.getFrameIndex(window.name);
                            location.reload(); //刷页面
                            parent.layer.close(index);
                        });
                    } else {
                        layer.alert(res.msg, { icon: 5 });
                    }
                }
            });
        });
    }

</script>

</html>